home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Development Kits / HyperCard Related / XCMDs & XFCNs / Help XFCN 1.4 / source / trap.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-13  |  2.4 KB  |  117 lines  |  [TEXT/MPS ]

  1. /*
  2.     trap.c
  3.     Functions to support testing for traps
  4.     and testing for Gestalt features.
  5.     
  6.     11-13-90 1.0d3 JRP    original (for Alias XFCN)
  7.     11-14-90 1.0d1 JRP    add helpMgrPresent
  8.                         change aliasAvailable to aliasMgrPresent
  9.     08-Apr-93 1.2d1    JRP    correct error in Gestalt parameter,
  10.                         was causing write-to-nil.
  11. */
  12.  
  13. #include    <Types.h>
  14. #include    <Traps.h>
  15. #include    <OSUtils.h>
  16. #include    <GestaltEqu.h>
  17.  
  18. #include    "trap.pro"
  19.  
  20. short helpMgrPresent(void)
  21. /*
  22.     Returns true if the Help Manager is present.
  23. */
  24. {
  25.     long    response;
  26.     short    result=false;
  27.  
  28.     if(gestaltAvailable())
  29.     {
  30.         if(Gestalt(gestaltHelpMgrAttr, &response)==noErr)
  31.         {
  32.                 // See if the gestaltHelpMgrPresent-th bit is set.
  33.             result = response & (1 << gestaltHelpMgrPresent);
  34.         }
  35.     }
  36.     return result;
  37. }    /*    --------------------------------------------    helpMgrPresent        */
  38.  
  39. short aliasMgrPresent(void)
  40. /*
  41.     Returns true if Alias Manager is present.
  42. */
  43. {
  44.     long    response;
  45.     short    result=false;
  46.  
  47.     if(gestaltAvailable())
  48.     {
  49.         if(Gestalt(gestaltAliasMgrAttr, &response)==noErr)
  50.         {
  51.                 // See if the gestaltAliasMgrPresent-th bit is set.
  52.             result = response & (1 << gestaltAliasMgrPresent);
  53.         }
  54.     }
  55.     return result;
  56. }    /*    --------------------------------------------    aliasMgrPresent        */
  57.  
  58. short gestaltAvailable(void)
  59. /*
  60.     Returns true if gestalt is available.
  61.     From IM-VI. chap 3, page 8
  62. */
  63. {
  64.     #define    _Gestalt    0xA1AD
  65.     
  66.     return(trapAvailable(_Gestalt));
  67. }    /*    --------------------------------------------    gestaltAvailable        */
  68.  
  69. short getTrapType(theTrap)
  70. /*
  71.     Returns the trap type.
  72.     From IM-VI. chap 3, page 8
  73. */
  74.     short    theTrap;
  75. {
  76.     #define    trapMask    0x0800
  77.     
  78.     if(theTrap & trapMask)
  79.         return ToolTrap;
  80.     else
  81.         return OSTrap;
  82. }    /*    --------------------------------------------    getTrapType        */
  83.  
  84. short numToolboxTraps(void)
  85. /*
  86.     Returns the number of toolbox traps.
  87.     From IM-VI. chap 3, page 8
  88. */
  89. {
  90.     if(NGetTrapAddress(_InitGraf, ToolTrap)==
  91.             NGetTrapAddress(0xAA6E, ToolTrap))
  92.                 return 0x200;
  93.     else
  94.         return 0x400;
  95. }    /*    --------------------------------------------    numToolboxTraps        */
  96.  
  97. short trapAvailable(theTrap)
  98. /*
  99.     Returns true if the trap is available.
  100.     From IM-VI. chap 3, page 8
  101. */
  102.     short    theTrap;
  103. {
  104.     short    tType;
  105.  
  106.     tType = getTrapType(theTrap);
  107.     if(tType==ToolTrap)
  108.     {
  109.         theTrap = theTrap & 0x07FF;
  110.         if(theTrap>=numToolboxTraps())
  111.             theTrap = _Unimplemented;
  112.     }
  113.     return(NGetTrapAddress(theTrap, tType)!=
  114.                 NGetTrapAddress(_Unimplemented, ToolTrap));
  115. }    /*    --------------------------------------------    trapAvailable    */
  116.  
  117.